package com.nali.dal.statement.query;

import java.util.Collections;
import java.util.List;
import java.util.Map;

import com.nali.dal.expression.PropertyExpression;
import com.nali.dal.expression.query.Criteria;
import com.nali.dal.statement.function.DataHandler;
import com.nali.dal.statement.function.DataHandlerFactory;

public class SimpleStatefulColumn implements ColumnUnitConfig {
	static class SimpleStatefulColumnUnit implements ColumnUnit {
		private String name;
		private DataHandler<?> handler;
		private List<Object> argList;
		public SimpleStatefulColumnUnit(String name, DataHandler<?> handler, List<Object> argList) {
			super();
			this.name = name;
			this.handler = handler;
			this.argList = argList;
		}

		public String getName() {
			return name;
		}

		public Object getColumnValue(Map<String, Object> datas) {
			return handler.handle(argList);
		}
	}
	private String name;
	private final String functionName;
	private final DataHandlerFactory dataHandlerFactory;
	private List<Object> argList;
	
	public SimpleStatefulColumn(String name, String functionName, DataHandlerFactory dataHandlerFactory, List<Object> argList) {
		this.name = name;
		this.functionName = functionName;
		this.dataHandlerFactory = dataHandlerFactory;
		this.argList = argList;
	}

	public List<String> getColumns() {
		return Collections.emptyList();
	}

	@Override
	public List<PropertyExpression<Criteria>> getColumnCriterias() {
		return Collections.emptyList();
	}

	@Override
	public ColumnUnit getColumnUnit() {
		DataHandler<?> dataHandler = dataHandlerFactory.getDataHandler(functionName);
		return new SimpleStatefulColumnUnit(name, dataHandler, argList);
	}
}
